<template>
	<div id="app">
		<router-view v-if="isRouterAlive"></router-view>
		<loading v-model="showLoading" :text="loadText"></loading>
	</div>
</template>

<script>
	export default {
		name: 'App',
		provide() {
			return {
				reload: this.reload
			}
		},
		data() {
			return {
				showLoading: true,
				loadText: '正在加载...',
				isRouterAlive: true
			}
		},
		methods: {
			reload() {
				this.isRouterAlive = false
				this.$nextTick(function() {
					this.isRouterAlive = true
				})
			}
		},
		created() {
			// 刚进来清除所有的缓存
			localStorage.clear();

			function GetRequest() {
				var url = location.search; //获取url中"?"符后的字串 
				var theRequest = new Object();
				if(url.indexOf("?") != -1) {
					var str = url.substr(1);
					let strs = str.split("&");
					for(var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			}
			//   存储token
			var data = GetRequest()
			if(data.token != null || data.token != undefined) {
				localStorage.setItem('token', data.token);
			}

		},
		mounted() {
			//   刚开始判定是否有人物，如果有人物就进入echarts页面，没人物就进入addperson页面
			this.$http.post('/health_record/easy_list.do')
				.then(({data}) => {
					
					this.showLoading = false;
					
					if(data.data.length == 0) {
						this.$router.push({
							path: '/addperson'
						})
					} else {
						this.$router.push({
							path: '/'
						})
					}
					// 刚开始进来的时候是没有customer_id，所以需要判断有没有customer_id，没有的话就存储第一个customer_id
					if(localStorage.getItem('customer_id') == null || localStorage.getItem('customer_id') == '') {
						localStorage.setItem('customer_id', data.data[0].customer_id);
						localStorage.setItem('realName', data.data[0].realName);
					}

				})
				.catch((err) => {
					console.log(err)
				})

		}
	}
</script>

<style>
	-webkit-backface-visibility: hidden;
	* {
		-webkit-backface-visibility: hidden;
	}
	
	.clearfix:after {
		visibility: hidden;
		display: block;
		font-size: 0;
		content: "";
		clear: both;
		height: 0;
	}
	
	.clearfix {
		*zoom: 1;
	}
	
	* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}
	
	html,
	body,
	#app {
		width: 100%;
		height: 100%;
	}
	
	#app .page {
		width: 100%;
		position: absolute;
		left: 0;
		bottom: 0;
		top: 0;
	}
	
	.header {
		background-color: rgb(58, 175, 252) !important;
	}
	
	i {
		font-style: normal;
	}
	
	ul,
	li {
		list-style: none;
	}
	
	.animated {
		-webkit-animation-duration: 0.4s;
		animation-duration: 0.4s;
		-webkit-animation-fill-mode: both;
		animation-fill-mode: both
	}
</style>

<style lang="less">
	@import '~vux/src/styles/reset.less';
</style>